package dao.impl;

import dao.i.BrandDao;
import entity.Brand;
import helper.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class BrandDaoImpl implements BrandDao {

    Connection connection = DataSource.getConnection();

    @Override
    public List<Brand> selectAllBrand() {
        Statement statement = null;
        ResultSet resultSet = null;
        List<Brand> brandList = new ArrayList<>();
        try {
            statement = connection.createStatement();
            resultSet = statement.executeQuery("select * from brand");
            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                String introduce=resultSet.getString("introduce");
                int adminId = resultSet.getInt("adminId");
                Brand brand=new Brand(id, name, introduce, adminId);
                brandList.add(brand);            
            }
            return brandList;
        } catch (SQLException ex) {
            try {
                statement.close();
            } catch (SQLException ex1) {
                ex1.printStackTrace();
            }
            try {
                resultSet.close();
            } catch (SQLException ex1) {
                    ex1.printStackTrace();
            }
              ex.printStackTrace();
        }
        return null;
    }

}
